

import {
  productgetBid
} from "../../api.js"
var app = getApp(); //获取App内部的信息
Page({

  /**
   * 页面的初始数据
   */
  data: {
    internet: true,
    load: false,
    top: false,
    lasttit: "",
    show: false,
    chuopai: true,
    url: "https://resource.growthupup.com/cha.png?t=2",
    allProductItems: [],
    page: 1,
    last_page: 1,
    last: "上期活动已经结束，本期正在火热筹备中"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.productBid(1, true)
    setTimeout(() => {
      if (this.data.load) {
        return
      } else {
        this.setData({
          internet: false,
          load: true
        })
      }
    }, 6000)

  },
  onShow() {
    this.setData({
      chuopai:true,
      show:false
    })
  },
  //下拉刷新
  onPullDownRefresh: function () {
    this.productBid(1, true)
    wx.stopPullDownRefresh()
  },
  // 上拉刷新
  onReachBottom: function () {
    timer ? clearTimeout(timer) : ""
    this.setData({
      lasttit: "正在加载"
    })
    this.data.page == this.data.last_page ? this.setData({
      lasttit: "暂无更多数据"
    }) : this.productBid(this.data.page + 1, false)
    var timer =setTimeout(()=>{
      this.setData({
        lasttit: ""
      })
    },2000)
  },

  //拍卖
  paimai() {
    this.setData({
      chuopai: false,
      show: true
    })
  },
  close() {
    this.setData({
      chuopai: true,
      show: false
    })
  },
  out(){
    wx.navigateTo({
      url: '../user/shopCar/shopCar?color='+true,
    })
  },
  service(){
    wx.navigateTo({
      url: '../user/setUp/setUp',
    })
  },
  productBid(page, bea) {
    var that = this
    productgetBid({
      token: app.globalData.token,
      page: page
    }).then(res => {
      bea ? that.setData({
        lasttit: "",
        allProductItems: res.data.data.data,
        load:true,
        internet:true,
        last_page: res.data.data.last_page,
        page: res.data.data.current_page
      }) : that.setData({
        lasttit: "",
          load: true,
          internet: true,
        allProductItems: that.data.allProductItems.concat(res.data.data.data),
        last_page: res.data.data.last_page,
        page: res.data.data.current_page
      })
    })
  }
})
